<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@include file="/WEB-INF/jsp/common/taglib.jsp"%>
<script type="text/javascript">
	var userList;
	$(function() {
		userList = lyGrid({
			pagId : 'paging',
			l_column : [{
				colkey : "username",
				name : "用户名",
				isSort : true
			}, {
				colkey : "accountname",
				name : "真实姓名",
				isSort : true
			}, {
				colkey : "rolename",
				name : "所属角色"
			}, {
				colkey : "locked",
				name : "账号状态",
				width : '90px',
				isSort : true
			}, {
				colkey : "description",
				name : "描述"
			}, {
				colkey : "createtime",
				name : "创建时间",
				width : '190px',
				isSort : true
				/* renderData : function(rowindex, data, rowdata, column) {
					return new Date(data).format("yyyy-MM-dd hh:mm:ss");
				} */
			}, {
				colkey : "id",
				name : "操作",
				renderData : function(rowindex, data, rowdata, colkeyn) {
					var s = '<input type="button" value="删除" onclick="del('+data+');"/>';
					return s;
				}
			}],
			jsonUrl : '${ctx}/user/findByPage.shtml',
			checkbox : true,
			//dymCol : true,
			serNumber : true
		});
		$("#add").click("click",function(){
			window.open("${ctx}/base/toPage.shtml?page=/system/user/addUser");
		});
		$("#li").click("click",function(){
			var data = userList.getColumn();
			var arr = new Array();
			for (var i = 0; i < data.length; i++) {
				arr.push(data[i]['name']);
				$('#ul_dmycol').append('<li>'+data[i]['name']+'</li>');
			}
			var display = document.getElementById("ul_dmycol").style.display;
			if(display === "none"){
				$('#ul_dmycol').css("display","block");
			}
			if(display === "block"){
				$('#ul_dmycol').css("display","none");
				$('#ul_dmycol li').each(function(){
					$(this).remove();
				})
				
			}
		});
		
		$("#edit").click("click",function(){
			var cbox = userList.getSelectedCheckbox();
			if(cbox.length > 1 || cbox == ""){
				alert("只能选中一个");
				return;
			}
			window.open("${ctx}/user/toEditUser.shtml?id="+cbox);
		})
		$("#permission").click("click",function(){
			var cbox = userList.getSelectedCheckbox();
			if(cbox.length > 1 || cbox == ""){
				alert("只能选中一个");
				return;
			}
			window.open("${ctx}/resources/toPermission.shtml?id="+cbox);
		});
		$("#search").click("click", function() {// 绑定查询按扭
			var searchParams = $("#searchForm").serializeJson();// 初始化传参数
			userList.setOptions({
				data : searchParams
			});
		});
		$("#export").click("click", function() {// 绑定查询按扭
			userList.exportData('${ctx }/user/export.shtml');
		});
	})
	function del(id){
		$.ajax({
			url:"${ctx}/user/delUser.shtml",
			data:{
				id: id
			},
			type:"post",
			dataType:"json",
			success : function(data){
				if(data){
					loadList();
				}else{
					alert("删除失败！");
				}
			}
		})
	}
	function loadList(){
		userList.loadData();
		parent.autoHeight();
	}
</script>
<div class="m-b-md">
	<form class="form-inline" role="form" id="searchForm" name="searchForm">
		<div class="form-group">
			<label class="control-label"> <span
				class="h4 font-thin v-middle">账号:</span></label> <input
				class="input-medium ui-autocomplete-input" id="username"
				name="username"/>
		</div>
		<input type="button" class="btn btn-default" id="search" value="查询"/>
		<input type="button" class="btn btn-info" id="export" value="导出excel"/>
	</form>
</div>
<header class="panel-heading">
	<div class="doc-buttons">
		<c:forEach items="${res}" var="key">
			${key.description}
		</c:forEach>
	</div>
</header>
<div class="table-responsive">
	<div id="paging" class="pagclass"></div>
</div>
<!-- <div id="dmy" class="dmycolClass" style="height: 10px;" >
	<li id="li" class="fa fa-thumb-tack" style="float: left;margin-top: 3px; cursor: pointer;">
		<ul id="ul_dmycol" class="dmycol-menu" style="display: none"></ul>
	</li>
</div> -->

